//
//  Three60Map.m
//  Dolphin
//
//  Created by alex tao on 2/15/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Three60Map.h"

@implementation Three60Map

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        useOneRow = FALSE;
        
        threeSixtyMap0 = [[ThreeSixtyMap alloc] initWithFrame:frame];
        threeSixtyMap0.delegate = self;
        threeSixtyMap0.hidden = TRUE;
        [self addSubview:threeSixtyMap0];
        
        threeSixtyMap1 = [[ThreeSixtyMap alloc] initWithFrame:frame];
        threeSixtyMap1.delegate = self;
        [self addSubview:threeSixtyMap1];
        
        threeSixtyMap2 = [[ThreeSixtyMap alloc] initWithFrame:frame];
        threeSixtyMap2.delegate = self;
        threeSixtyMap2.hidden = TRUE;
        [self addSubview:threeSixtyMap2];
        
        curMapIndex = 1;
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void) setPictureArrayMid:(int) inTopStartIndex
                topEndIndex:(int) inTopEndIndex
              midStartIndex:(int) inMidStartIndex
                midEndIndex:(int) inMidEndIndex
           bottomStartIndex:(int) inBottomStartIndex
             bottomEndIndex:(int) inBottomEndIndex
                     prefix:(NSString *) inPrefix
{
    NSMutableArray *arrA = [[NSMutableArray alloc] init];
    NSMutableArray *arrB = [[NSMutableArray alloc] init];
    NSMutableArray *arrC = [[NSMutableArray alloc] init];
    
    NSString *tempFileName;
    
    for (int i = inTopStartIndex; i<= inTopEndIndex; i++) 
    {
        if (i%2 == 1 || i == inTopStartIndex || i == inTopEndIndex) 
        {
            if (i<10) 
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@u0%d",inPrefix,i];
            }
            else
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@u%d",inPrefix,i];
            }
            [arrA addObject:tempFileName];
        }
    }
    
    for (int i = inMidStartIndex; i<= inMidEndIndex; i++) 
    {
        if (i%2 == 1 || i == inMidStartIndex || i == inMidEndIndex) 
        {
            if (i<10) 
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@m0%d",inPrefix,i];
            }
            else
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@m%d",inPrefix,i];
            }
            
            [arrB addObject:tempFileName];
        }
    }
    
    for (int i = inBottomStartIndex; i<= inBottomEndIndex; i++) 
    {
        if (i%2 == 1 || i == inBottomStartIndex || i == inBottomEndIndex) 
        {
            if (i<10) 
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@b0%d",inPrefix,i];
            }
            else
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@b%d",inPrefix,i];
            }
            [arrC addObject:tempFileName];
        }
    }

    [threeSixtyMap0 initTheMap:arrA fileType:@"jpg" inId:0];
    [threeSixtyMap1 initTheMap:arrB fileType:@"jpg" inId:1];
    [threeSixtyMap2 initTheMap:arrC fileType:@"jpg" inId:2];
}

- (void) setPictureArrayOneRow:(int) inTopStartIndex
                   topEndIndex:(int) inTopEndIndex
                        prefix:(NSString *) inPrefix
{
    NSMutableArray *arrA = [[NSMutableArray alloc] init];
    NSString *tempFileName;
    
    for (int i = inTopStartIndex; i<= inTopEndIndex; i++) 
    {
        if (i%2 == 1 || i == inTopStartIndex || i == inTopEndIndex) 
        {
            if (i<10) 
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@0%d",inPrefix,i];
            }
            else
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@%d",inPrefix,i];
            }
            [arrA addObject:tempFileName];
        }
    }
    
    useOneRow = TRUE;
    [threeSixtyMap0 initTheMap:arrA fileType:@"jpg" inId:0];
    
    threeSixtyMap0.hidden = TRUE;
    threeSixtyMap1.hidden = TRUE;
    threeSixtyMap2.hidden = TRUE;
    threeSixtyMap0.hidden = FALSE;
}

-(void) updateMapWithId:(int) inId 
           curPageIndex:(int) inIndex
{
    if (useOneRow) 
    {
        return;
    }
    
    threeSixtyMap0.hidden = TRUE;
    threeSixtyMap1.hidden = TRUE;
    threeSixtyMap2.hidden = TRUE;
    
    if (inId == 0) 
    {
        threeSixtyMap0.hidden = FALSE;
    }
    else if(inId == 1)
    {
        threeSixtyMap1.hidden = FALSE;
    }
    else if(inId == 2)
    {
        threeSixtyMap2.hidden = FALSE;
    }
}

-(void) setRowNotJudge
{
    threeSixtyMap0.useJudge = FALSE;
}

- (void) swipeUpWithMapId:(int)mapId
{
    if (useOneRow) 
    {
        return;
    }
    
    if (curMapIndex<2) 
    {
        curMapIndex++;
        [self updateMapWithId:curMapIndex curPageIndex:mapId];
    }
}

- (void) swipeDownWithMapId:(int)mapId
{
    if (useOneRow) 
    {
        return;
    }
    
    if (curMapIndex>0) 
    {
        curMapIndex--;
        [self updateMapWithId:curMapIndex curPageIndex:mapId];
    }
}

-(void) reset
{
    if (threeSixtyMap0) 
    {
        [threeSixtyMap0 reset];
        [threeSixtyMap0 removeFromSuperview];
        [threeSixtyMap0 release];
    }

    if (threeSixtyMap1) 
    {
        [threeSixtyMap1 reset];
        [threeSixtyMap1 removeFromSuperview];
        [threeSixtyMap1 release];
    }
    
    if (threeSixtyMap2)
    {
        [threeSixtyMap2 reset];
        [threeSixtyMap2 removeFromSuperview];
        [threeSixtyMap2 release];
    }

}


@end
